﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using VPBS.Common;

namespace VPBS.Informix.DAL
{
    public class TcmstMarginSecuritiesDAL
    {
        /// <summary>
        /// Lay ty le Margin cua chung khoan
        /// </summary>
        /// <param name="Sharecode"></param>
        /// <returns>Margin Securities</returns>
        public static decimal Get_MarginSecurities(string Sharecode, string DateQuery)
        {
            try
            {
                //string command = "select FIRST 1 margrate from Tcmst where sharecode='" + Sharecode + "' and effdate <= today order by effdate desc";

                string command =
                    @"select first 1 margrate from Tcmst where trim(sharecode)='" + Sharecode + "' and '" + DateQuery +
                    "' between effdate and enddate order by sharecode";

                DataSet ds = InformixOdbcHelper.ExecuteDataset(ConnectStringHelper.InfxOdbcConnectionString, CommandType.Text,
                                                   command);
                if (ds != null && ds.Tables.Count > 0)
                    return decimal.Parse(ds.Tables[0].Rows[0][0].ToString());
                return 100M;
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_MarginSecurities), ex);
                return 100M;
            }
        }
    }
}
